package com.hzhr.iot.device.service.helper;

import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.toll.sdk.model.gasUser.GasUserModel;
import com.hzhr.iot.toll.sdk.service.Toll_GasUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class Toll_GasUserServiceHelper {
    @Autowired
    Toll_GasUserService toll_gasUserService;

    public GasUserModel getByCodeAndCompanyId(Map<String, String> header, String code, Integer companyId) throws ServiceException {
        Map<String, Object> query = new HashMap<>();
        query.put("_equal_companyId", companyId);
        query.put("_equal_code", code);
        query.put("_show", "one");
        query.put("_show_info", true);
        GasUserModel gasUser = toll_gasUserService.get(header, query).getModel();
        return gasUser;
    }

    public GasUserModel getByCodeAndDeptId(Map<String, String> header, String code, Integer deptId) throws ServiceException {
        Map<String, Object> query = new HashMap<>();
        query.put("equal_deptId", deptId);
        query.put("_equal_code", code);
        query.put("_show", "one");
        query.put("_show_info", true);
        GasUserModel gasUser = toll_gasUserService.get(header, query).getModel();
        return gasUser;
    }

    public int getCountByCodeAndCompanyId(Map<String, String> header, String code, Integer companyId) throws ServiceException {
        Map<String, Object> query = new HashMap<>();
        query.put("_equal_companyId", companyId);
        query.put("_equal_code", code);
        query.put("_show_total", true);
        int count = toll_gasUserService.get(header, query).getTotal();
        return count;
    }
}
